<template>

    <!-- 添加或修改对话框 -->
    <lam-dialog :title="title" :visible.sync="open" width="680px" append-to-body @close="cancel">
      <el-form :ref="formRef" :model="form" :rules="rules" label-width="100px" :disabled="formDisabled">
        <el-row>
          <el-col :span="12">
            <el-form-item label="店铺名称" prop="shopName">
              <lam-dict-select v-model="form.shopName" dictCode="shop_name_type" placeholder="" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店长用户id" prop="userId">
              <el-input v-model="form.userId" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺类型" prop="shopType">
              <lam-dict-select v-model="form.shopType" dictCode="" placeholder="" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="店铺简介" prop="intro">
              <el-input v-model="form.intro" type="textarea" autosize placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺公告" prop="shopNotice">
              <el-input v-model="form.shopNotice" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺行业" prop="shopIndustry">
              <el-input-number v-model="form.shopIndustry" clearable controls-position="right" :min="0" style="width: 100%;"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店长" prop="shopOwner">
              <el-input v-model="form.shopOwner" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺绑定的手机" prop="mobile">
              <el-input v-model="form.mobile" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺联系电话" prop="tel">
              <el-input v-model="form.tel" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺所在纬度" prop="shopLat">
              <el-input v-model="form.shopLat" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺所在经度" prop="shopLng">
              <el-input v-model="form.shopLng" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺详细地址" prop="shopAddress">
              <el-input v-model="form.shopAddress" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺所在省份" prop="province">
              <el-input v-model="form.province" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺所在城市" prop="city">
              <el-input v-model="form.city" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺所在区域" prop="area">
              <el-input v-model="form.area" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺省市区代码，用于回显" prop="pcaCode">
              <el-input v-model="form.pcaCode" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="店铺logo" prop="shopLogo">
              <el-input v-model="form.shopLogo" type="textarea" autosize placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="店铺相册" prop="shopPhotos">
              <el-input v-model="form.shopPhotos" type="textarea" autosize placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="每天营业时间段" prop="openTime">
              <el-input v-model="form.openTime" clearable placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="店铺状态" prop="shopStatus">
              <lam-dict-select v-model="form.shopStatus" dictCode="shop_status" placeholder="" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="0:商家承担运费; 1:买家承担运费" prop="transportType">
              <el-input-number v-model="form.transportType" clearable controls-position="right" :min="0" style="width: 100%;"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="固定运费" prop="fixedFreight">
              <el-input-number v-model="form.fixedFreight" clearable controls-position="right" :min="0" style="width: 100%;"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="满X包邮" prop="fullFreeShipping">
              <el-input-number v-model="form.fullFreeShipping" clearable controls-position="right" :min="0" style="width: 100%;"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分销开关" prop="isDistribution">
              <lam-dict-select type="radio" v-model="form.isDistribution" dictCode="distribution_type" placeholder="" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :loading="loading">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </lam-dialog>
    
</template>

<script>
import { EditMixin } from '@/components/mixins/EditMixin';

export default {
  name: "EditShopDetail",
  mixins:[EditMixin],
  data() {
    return {
      url: {
        base: '/mall/shopDetail/'
      },
      // 表单校验
      rules: {
        shopName: [{validator: this.shopNameUniqueValidator, trigger: 'blur'}],
      },
    };
  },
  created() {
  },
  methods: {
    // 表单重置
    reset() {
      this.form = {
        shopName: "0",
        userId: null,
        shopType: 0,
        intro: null,
        shopNotice: null,
        shopIndustry: null,
        shopOwner: null,
        mobile: null,
        tel: null,
        shopLat: null,
        shopLng: null,
        shopAddress: null,
        province: null,
        city: null,
        area: null,
        pcaCode: null,
        shopLogo: null,
        shopPhotos: null,
        openTime: null,
        shopStatus: 0,
        transportType: null,
        fixedFreight: null,
        fullFreeShipping: null,
        isDistribution: 0
      };
    },

    shopNameUniqueValidator(rule, value, callback) {
      if(!value){
        callback(); return;
      }
      let param = {shopName: value};
      if(this.operType=='update') param.id = this.form.id;
      this.checkUniqueAsyn(value, callback, 'shopDetailShopName', param);
    },
    
    /** 提交按钮 */
    submitForm(){
      this.saveForm(this.url.base);
    }

  }
};
</script>
